//
//  BTEListBTableViewCell.swift
//  BTE
//  列表 item
//  Created by Mike Zhang on 2025/8/19.
//

import UIKit

class BTEListBTableViewCell: UITableViewCell {
    
    var model: BTHOMtiniestmodel? {
        didSet {
            guard let m = model else {
                return
            }
            ttittt.text = m.cuspid
            timage.sd_setImage(with: URL.init(string: m.butyrins!))
            button.setTitle(title: " \(m.allergin!) ")
            a1.text = m.semiorganized
            a11.text = m.cesura
            a2.text = m.plumiped
            a22.text = m.tergal
        }
    }

    fileprivate let bg = UIImageView.init(image: UIImage.init(named: "Group 1171276dddddddd686"))
    
    let timage = UIImageView()
    
    let ttittt = UILabel.init()
    
    let button = UIButton()
    
    let a1 = UILabel()
    
    let a11 = UILabel()
    
    let a2 = UILabel()
    
    let a22 = UILabel()
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.addSubview(bg)
        bg.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview().inset(5)
            make.left.right.equalToSuperview().inset(16)
        }
        
        bg.addSubview(timage)
        bg.addSubview(ttittt)
        bg.addSubview(button)
        
        timage.roundCorners(.allCorners, radius: 6)
        timage.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.top.equalToSuperview().offset(20)
            make.width.equalTo(30)
            make.height.equalTo(30)
        }
        
       
        ttittt.font = .systemFont(ofSize: 18)
        ttittt.textColor = .black
        ttittt.snp.makeConstraints { make in
            make.centerY.equalTo(timage)
            make.left.equalTo(timage.snp.right).offset(8)
        }
        
        button.contentEdgeInsets = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 6)
        button.roundCorners(.allCorners, radius: 15)
        button.layer.borderWidth = 2
        button.layer.borderColor = UIColor.colorWithHex("#6C2724")?.cgColor
        button.setTitleColor(UIColor.colorWithHex("#6C2724")!)
        button.setFont(.systemFont(ofSize: 16))
        button.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-16)
            make.centerY.equalTo(timage)
            make.height.equalTo(30)
            
        }
        
        [a1,a2].forEach { item in
            item.font = .systemFont(ofSize: 14)
            item.textColor = .black
        }
        
        [a11,a22].forEach { item in
            item.font = .systemFont(ofSize: 16)
            item.textColor = .colorWithHex("#187CA5")
        }
        
        let a1bo = UIView()
        bg.addSubview(a1bo)
        a1bo.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.right.equalTo(button.snp.right)
            make.top.equalTo(button.snp.bottom).offset(10)
        }
        
   
        
        a1bo.addSubview(a1)
        a1bo.addSubview(a11)
        a1.snp.makeConstraints { make in
            make.top.left.bottom.equalToSuperview()
        }
        
        a11.snp.makeConstraints { make in
            make.right.top.bottom.equalToSuperview()
        }
        
        
        let a2bo = UIView()
        bg.addSubview(a2bo)
        a2bo.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.right.equalTo(button.snp.right)
            make.top.equalTo(a1bo.snp.bottom).offset(10)
        }
        
  
        a2bo.addSubview(a2)
        a2bo.addSubview(a22)
        a2.snp.makeConstraints { make in
            make.top.left.bottom.equalToSuperview()
        }
        
        a22.snp.makeConstraints { make in
            make.right.top.bottom.equalToSuperview()
        }
        
    }
    
    

}
